/* Copyright (C) 2010 Luca Piccinelli
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* 
 * File:   AbstractDirectoryGenerator.h
 * Author: picci
 *
 * Created on December 18, 2010, 12:51 PM
 */

#ifndef ABSTRACTDIRECTORYGENERATOR_H
#define	ABSTRACTDIRECTORYGENERATOR_H

#include "generators/resource/AbstractResourceGenerator.h"
#include "exceptions/generator_exceptions.h"

#include "boost/filesystem.hpp"

#include <string>

namespace NAMESPACE{

class AbstractDirectoryGenerator : public AbstractResourceGenerator{
public:
    using AbstractGenerator::generate;
    using AbstractGenerator::set_key;
protected:
    virtual void free_element(IOElement* el) = 0;
    virtual memory_size_t measure_memory() = 0;
    
    std::vector<boost::filesystem::path>::iterator elem_it;
    std::vector<boost::filesystem::path> d_elems;
    std::string next_element();

public:
    virtual ~AbstractDirectoryGenerator();
    AbstractDirectoryGenerator();
    AbstractDirectoryGenerator(const AbstractDirectoryGenerator& g);
    AbstractDirectoryGenerator& operator=(const AbstractDirectoryGenerator& g);

    AbstractDirectoryGenerator(const std::string& _resource, 
                               const memory_size_t& _max_mem = AbstractGenerator::DEFAULT_MAX_MEM_SIZE);
    AbstractDirectoryGenerator(const IOKey& k, 
                               const memory_size_t& _max_mem = AbstractGenerator::DEFAULT_MAX_MEM_SIZE);
    AbstractDirectoryGenerator(const std::string& _resource,
                               const IOKey& k,
                               const memory_size_t& _max_mem = AbstractGenerator::DEFAULT_MAX_MEM_SIZE);

    virtual Generator& set_key(const std::string& ns, const std::string& key_name) = 0;

    virtual AbstractDirectoryGenerator& open() throw(bad_resource);
    virtual AbstractDirectoryGenerator& close();

    virtual IOElement* generate(const IOKey& key) = 0;
};

}

#endif	/* ABSTRACTDIRECTORYGENERATOR_H */

